package com.guguskins.back.controller;
import com.guguskins.back.entity.GuCarouselMap;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuCarouselMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 轮播图表 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-07-08
 */
@RestController
@RequestMapping("/carouselMap")
public class GuCarouselMapController {
    @Autowired
    private GuCarouselMapService guCarouselMapService;

    @GetMapping("list")
    public ResultVo list(@RequestParam(value = "cmType",required = false) int cmType) {
        return ResultVo.success(guCarouselMapService.availableList(cmType));
    }
    /**
     * 查找全部轮播图
     */
    @GetMapping("/back/list")
    public ResultVo backList(@RequestParam(value = "cmType",required = false) int cmType) {

        return ResultVo.success(guCarouselMapService.findByCmType(cmType));
    }

    /**
     * 查找轮播图的方法
     */
    @GetMapping("/back/findById")
    public ResultVo backFindById(@RequestParam(value = "cmId",required = false) Integer cmId) {

        return ResultVo.success(guCarouselMapService.findById(cmId), "成功");
    }
    /**
     * @param guCarouselMap 添加轮播图的方法
     * @return
     */
    @PostMapping("/back/insert")
    public ResultVo backInsert(@RequestBody GuCarouselMap guCarouselMap) {
        guCarouselMapService.insert(guCarouselMap);
        return ResultVo.success("添加成功");
    }
    /**
     * @param guCarouselMap 修改轮播图的方法
     * @return
     */
    @PostMapping("/back/update")
    public ResultVo backUpdate(@RequestBody GuCarouselMap guCarouselMap) {
        guCarouselMapService.updateById(guCarouselMap);
        return ResultVo.success("修改成功");
    }
    @GetMapping("back/delete")
    public  ResultVo backDelece(@RequestParam(value = "cmId" ,required = false)Integer cmId){
        GuCarouselMap carouselMap=new GuCarouselMap();
        carouselMap.setCmId(cmId);
        carouselMap.setCmEnable(false);
        guCarouselMapService.updateById(carouselMap);
        return ResultVo.success("删除成功");
    }
}
